package com.example.communitysystem.controller;

import com.example.communitysystem.dto.PaginationDTO;
import com.example.communitysystem.dto.QuestionDTO;
import com.example.communitysystem.mapper.QuestionMapper;
import com.example.communitysystem.mapper.UserMapper;
import com.example.communitysystem.model.Question;
import com.example.communitysystem.model.User;
import com.example.communitysystem.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class IndexController {
    private QuestionService questionService; //操作问题信息和用户关联的service
    @RequestMapping("/")
    public String index(
            HttpServletRequest request,
            Model model,
            @RequestParam(name = "page", defaultValue = "1")Integer page,
            @RequestParam(name = "size", defaultValue = "5")Integer size
    ){
        PaginationDTO paginationDTO = questionService.getQuestionDTOList(page,size);
        model.addAttribute("paginationDTO", paginationDTO);
        System.out.println(paginationDTO);
        return "index";
    }

    @Autowired
    public void setQuestionService(QuestionService questionService) {
        this.questionService = questionService;
    }
}
